package benchmark;

import java.util.Arrays;

import utils.Tools;
import utils.Tools.OutputType;

public class RandomwalkArray extends AbstractBenchmarkST {

	private final static String ARRAY_SIZE = "arraysize";

	private static final int PRIME_INC = 514229;
	
	long[] data;
	
	public RandomwalkArray(String[] args) throws Exception {
		super(args);

		this.argReadme.put(ARRAY_SIZE, "Array size.");
		
		data = Tools.newMem(getArg(ARRAY_SIZE));
	}
	
	void testRandom(String outputFile) {
		int pos = -1;
		int arraySize = data.length;
		String result = "";
		System.out.println(arraySize);
		for (int i = 0; i < arraySize; i++) {
			pos = (pos + PRIME_INC) % arraySize;
			result += Long.toString(pos) + "\n";
		}
		Tools.toFile(result, outputFile);
	}

	@Override
	protected long compute() {
		long sum = 0;
		int pos = -1;
		int arraySize = data.length;
		for (int i = 0; i < data.length; i++) {
			pos = (pos + PRIME_INC) % arraySize;
			sum += data[pos];
		}
		return sum;
	}

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		Tools.output(Arrays.toString(args), OutputType.DEBUG);
		RandomwalkArray b = new RandomwalkArray(args);
		b.run();
	}

}
